home *** CD-ROM | disk | FTP | other *** search
/ PC Basics 53 / PC Basics Issue 53.iso / Software / Internet / Invboard.exe / PC Basics 53 / Invboard / upload / sources / Admin / ad_forums.php < prev    next >
Encoding:
PHP Script  |  2002-06-12  |  58.8 KB  |  1,960 lines

  1. <?php
  2.  
  3. /*
  4. +--------------------------------------------------------------------------
  5. |   IBFORUMS v1
  6. |   ========================================
  7. |   by Matthew Mecham and David Baxter
  8. |   (c) 2001,2002 IBForums
  9. |   http://www.ibforums.com
  10. |   ========================================
  11. |   Web: http://www.ibforums.com
  12. |   Email: phpboards@ibforums.com
  13. |   Licence Info: phpib-licence@ibforums.com
  14. +---------------------------------------------------------------------------
  15. |
  16. |   > Admin Forum functions
  17. |   > Module written by Matt Mecham
  18. |   > Date started: 1st march 2002
  19. |
  20. |    > Module Version Number: 1.0.0
  21. +--------------------------------------------------------------------------
  22. */
  23.  
  24.  
  25.  
  26.  
  27.  
  28. $idx = new ad_forums();
  29.  
  30.  
  31. class ad_forums {
  32.  
  33.     var $base_url;
  34.  
  35.     function ad_forums() {
  36.         global $IN, $root_path, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP;
  37.  
  38.         switch($IN['code'])
  39.         {
  40.             case 'new':
  41.                 $this->new_form();
  42.                 break;
  43.             case 'donew':
  44.                 $this->do_new();
  45.                 break;
  46.             //+-------------------------
  47.             case 'edit':
  48.                 $this->edit_form();
  49.                 break;
  50.             case 'doedit':
  51.                 $this->do_edit();
  52.                 break;
  53.             //+-------------------------
  54.             case 'pedit':
  55.                 $this->perm_edit_form();
  56.                 break;
  57.             case 'pdoedit':
  58.                 $this->perm_do_edit();
  59.                 break;
  60.             //+-------------------------
  61.             case 'reorder':
  62.                 $this->reorder_form();
  63.                 break;
  64.             case 'doreorder':
  65.                 $this->do_reorder();
  66.                 break;
  67.             //+-------------------------
  68.             case 'delete':
  69.                 $this->delete_form();
  70.                 break;
  71.             case 'dodelete':
  72.                 $this->do_delete();
  73.                 break;
  74.             //+-------------------------
  75.             case 'recount':
  76.                 $this->recount();
  77.                 break;
  78.             //+-------------------------
  79.             case 'empty':
  80.                 $this->empty_form();
  81.                 break;
  82.             case 'doempty':
  83.                 $this->do_empty();
  84.                 break;
  85.             //+-------------------------
  86.             case 'frules':
  87.                 $this->show_rules();
  88.                 break;
  89.             case 'dorules':
  90.                 $this->do_rules();
  91.                 break;
  92.             //+-------------------------
  93.             case 'newsp':
  94.                 $this->new_splash();
  95.                 break;
  96.             case 'donewsplash':
  97.                 $this->donew_splash();
  98.                 break;
  99.             case 'donewsub':
  100.                 $this->add_sub();
  101.                 break;
  102.             //+-------------------------
  103.             case 'subedit':
  104.                 $this->subedit();
  105.                 break;
  106.             case 'doeditsub':
  107.                 $this->doeditsub();
  108.                 break;
  109.                 
  110.             case 'subdelete':
  111.                 $this->subdeleteform();
  112.                 break;
  113.             case 'dosubdelete':
  114.                 $this->dosubdelete();
  115.                 break;
  116.             //+-------------------------
  117.             case 'skinedit':
  118.                 $this->skin_edit();
  119.                 break;
  120.             case 'doskinedit':
  121.                 $this->do_skin_edit();
  122.                 break;
  123.             //+-------------------------    
  124.             default:
  125.                 $this->new_form();
  126.                 break;
  127.         }
  128.         
  129.     }
  130.     
  131.     
  132.     //+---------------------------------------------------------------------------------
  133.     //
  134.     // Edit forum skins
  135.     //
  136.     //+---------------------------------------------------------------------------------
  137.     
  138.     function skin_edit() {
  139.         global $IN, $root_path, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP;
  140.         
  141.         if ($IN['f'] == "")
  142.         {
  143.             $ADMIN->error("Could not determine the forum ID to empty.");
  144.         }
  145.         
  146.         $DB->query("SELECT id, name, skin_id FROM ibf_forums WHERE id='".$IN['f']."'");
  147.         
  148.         //+-------------------------------
  149.         // Make sure we have a legal forum
  150.         //+-------------------------------
  151.         
  152.         if ( !$DB->get_num_rows() )
  153.         {
  154.             $ADMIN->error("Could not resolve that forum ID");
  155.         }
  156.         
  157.         $forum = $DB->fetch_row();
  158.         
  159.         if ( ($forum['skin_id'] == "") or ($forum['skin_id'] == -1) )
  160.         {
  161.             $forum['skin_id'] = 'n';
  162.         }
  163.         
  164.         $form_array = array();
  165.         
  166.         $form_array[] = array( 'n', '-- NONE --' );
  167.         
  168.         $DB->query("SELECT sid, sname FROM ibf_skins");
  169.         
  170.         while ($r = $DB->fetch_row())
  171.         {
  172.             $form_array[] = array( $r['sid'], $r['sname'] );
  173.         }
  174.         
  175.         
  176.         //+-------------------------------
  177.         
  178.         $ADMIN->page_title = "Forum Skin Options";
  179.         $ADMIN->page_detail  = "You may choose to either add or remove a skin set to this forum. The skin choice will override the users choice.";
  180.         
  181.         $ADMIN->html .= $SKIN->start_form( array( 1 => array( 'code'  , 'doskinedit'),
  182.                                                   2 => array( 'act'   , 'forum'  ),
  183.                                                   3 => array( 'f'     , $IN['f'] ),
  184.                                             ) );
  185.         
  186.         
  187.         $SKIN->td_header[] = array( " "   , "40%" );
  188.         $SKIN->td_header[] = array( " "   , "60%" );
  189.         
  190.         $ADMIN->html .= $SKIN->start_table( "Skin choices for forum: {$forum['name']}" );
  191.         
  192.         $ADMIN->html .= $SKIN->add_td_row( array( "<b>Apply which skin?</b>" ,
  193.                                                   $SKIN->form_dropdown("fsid", $form_array, $forum['skin_id'] )
  194.                                          )      );
  195.                                          
  196.         $ADMIN->html .= $SKIN->end_form("Edit forum skin options");
  197.                                          
  198.         $ADMIN->html .= $SKIN->end_table();
  199.         
  200.         $ADMIN->output();
  201.         
  202.     }
  203.     
  204.     function do_skin_edit() {
  205.         global $IN, $root_path, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP;
  206.         
  207.         if ($IN['f'] == "")
  208.         {
  209.             $ADMIN->error("Could not determine the forum ID to empty.");
  210.         }
  211.         
  212.         $DB->query("SELECT id, name, skin_id FROM ibf_forums WHERE id='".$IN['f']."'");
  213.         
  214.         //+-------------------------------
  215.         // Make sure we have a legal forum
  216.         //+-------------------------------
  217.         
  218.         if ( !$DB->get_num_rows() )
  219.         {
  220.             $ADMIN->error("Could not resolve that forum ID");
  221.         }
  222.         
  223.         if ($IN['fsid'] == 'n')
  224.         {
  225.             $DB->query("UPDATE ibf_forums SET skin_id='-1' WHERE id='".$IN['f']."'");
  226.             $ADMIN->rebuild_config( array( 'forum_skin_'.$IN['f'] => "" ) );
  227.         }
  228.         else
  229.         {
  230.             $DB->query("UPDATE ibf_forums SET skin_id='".$IN['fsid']."' WHERE id='".$IN['f']."'");
  231.             $ADMIN->rebuild_config( array( 'forum_skin_'.$IN['f'] => $IN['fsid'] ) );
  232.         }
  233.         
  234.         
  235.         
  236.         $std->boink_it($ADMIN->base_url."&act=cat" );
  237.         exit();
  238.         
  239.     }
  240.     
  241.     //+---------------------------------------------------------------------------------
  242.     //
  243.     // Sub Cat Delete Form
  244.     //
  245.     //+---------------------------------------------------------------------------------
  246.     
  247.     function subdeleteform() {
  248.         global $IN, $root_path, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP;
  249.         
  250.         $form_array = array();
  251.         
  252.         if ($IN['f'] == "")
  253.         {
  254.             $ADMIN->error("Could not determine the forum ID to delete.");
  255.         }
  256.         
  257.         $cats = array();
  258.         
  259.         $name = "";
  260.         
  261.         $last_cat_id = -1;
  262.         
  263.         $DB->query("SELECT c.id, c.name, f.id as forum_id, f.subwrap, f.name as forum_name, f.parent_id, f.category FROM ibf_categories c, ibf_forums f WHERE c.id > 0 ORDER BY c.position, f.position");
  264.         
  265.         while ( $r = $DB->fetch_row() )
  266.         {
  267.         
  268.             if ($last_cat_id != $r['id'])
  269.             {
  270.                 $cats[] = array( "c_".$r['id'] , "Category: ".$r['name'] );
  271.                 
  272.                 $last_cat_id = $r['id'];
  273.             }
  274.             
  275.             if ($r['parent_id'] > 0)
  276.             {
  277.                 continue;
  278.             }
  279.             
  280.             if ($r['forum_id'] == $IN['f'])
  281.             {
  282.                 $name = $r['forum_name'];
  283.                 continue;
  284.             }
  285.             
  286.             if ($r['subwrap'] != 1)
  287.             {
  288.                 continue;
  289.             }
  290.             
  291.             if ($r['category'] == $r['id'])
  292.             {
  293.             
  294.                 $cats[] = array( "f_".$r['forum_id'], "Sub Category Forum: ".$r['forum_name'] );
  295.             }
  296.             
  297.         }
  298.         
  299.         //+-------------------------------
  300.         // Make sure we have more than 1
  301.         // forum..
  302.         //+-------------------------------
  303.         
  304.         if ($DB->get_num_rows() < 2)
  305.         {
  306.             $ADMIN->error("Can not remove this forum, please create another category or sub cat forum before attempting to remove this one");
  307.         }
  308.         
  309.         //+-------------------------------
  310.         
  311.         $ADMIN->page_title = "Removing Sub Category forum '$name'";
  312.         
  313.         $ADMIN->page_detail = "Before we remove this forum, we need to determine what to do with any sub forums you have in the sub category.";
  314.         
  315.         //+-------------------------------
  316.         
  317.         $ADMIN->html .= $SKIN->start_form( array( 1 => array( 'code'  , 'dosubdelete'),
  318.                                                   2 => array( 'act'   , 'forum'     ),
  319.                                                   3 => array( 'f'     , $IN['f']  ),
  320.                                             ) );
  321.         
  322.         //+-------------------------------
  323.         
  324.         $SKIN->td_header[] = array( " "  , "40%" );
  325.         $SKIN->td_header[] = array( " "  , "60%" );
  326.         
  327.         //+-------------------------------
  328.         
  329.         $ADMIN->html .= $SKIN->start_table( "Required" );
  330.         
  331.         $ADMIN->html .= $SKIN->add_td_row( array( "<b>Forum to remove: </b>" , $name )      );
  332.                                          
  333.         $ADMIN->html .= $SKIN->add_td_row( array( "<b>Move all <i>existing forums</i> to which parent?</b>" ,
  334.                                                   $SKIN->form_dropdown( "MOVE_ID", $cats )
  335.                                          )      );
  336.                                          
  337.         $ADMIN->html .= $SKIN->end_form("Move sub forums and remove this forum");
  338.                                          
  339.         $ADMIN->html .= $SKIN->end_table();
  340.         
  341.         $ADMIN->output();
  342.         
  343.         
  344.     }
  345.     
  346.     
  347.     function dosubdelete() {
  348.         global $IN, $root_path, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP;
  349.         
  350.         if ($IN['f'] == "")
  351.         {
  352.             $ADMIN->error("Could not determine the source forum ID.");
  353.         }
  354.         
  355.         if ($IN['MOVE_ID'] == "")
  356.         {
  357.             $ADMIN->error("Could not determine the destination parent ID.");
  358.         }
  359.         
  360.         $cat    = -1;
  361.         $parent = -1;
  362.         
  363.         if ( preg_match( "/^c_(\d+)$/", $IN['MOVE_ID'], $match ) )
  364.         {
  365.             $cat = $match[1];
  366.         }
  367.         else
  368.         {
  369.             $parent = preg_replace( "/^f_/", "", $IN['MOVE_ID'] );
  370.         }
  371.         
  372.         // Move sub forums...
  373.         
  374.         $DB->query("UPDATE ibf_forums SET category='$cat', parent_id='$parent' WHERE parent_id='".$IN['f']."'");
  375.         
  376.         $DB->query("DELETE FROM ibf_forums WHERE id='".$IN['f']."'");
  377.         
  378.         $ADMIN->done_screen("Forum Removed", "Forum Control", "act=cat" );
  379.         
  380.     }
  381.     
  382.     //+---------------------------------------------------------------------------------
  383.     //
  384.     // Sub Cat Edit Form
  385.     //
  386.     //+---------------------------------------------------------------------------------
  387.     
  388.     
  389.     function subedit() {
  390.         global $IN, $root_path, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP, $HTTP_GET_VARS;
  391.         
  392.         
  393.         $cats = array();
  394.         
  395.         $last_cat_id = -1;
  396.         
  397.         $DB->query("SELECT * from ibf_categories WHERE id > 0 ORDER BY position");
  398.         
  399.         while ( $r = $DB->fetch_row() )
  400.         {
  401.             $cats[] = array( $r['id'] , "Category: ".$r['name'] );
  402.         }
  403.         
  404.         $DB->query("SELECT * from ibf_forums WHERE subwrap='1' AND id='".$IN['f']."'");
  405.         
  406.         if (! $forum = $DB->fetch_row() )
  407.         {
  408.             $ADMIN->error("Could not find that sub category forum in the database");
  409.         }
  410.             
  411.         
  412.         $ADMIN->page_title = "Editing a Sub Category Forum";
  413.         
  414.         $ADMIN->page_detail = "This section will allow you edit a sub category forum.";
  415.         
  416.         //+-------------------------------
  417.         
  418.         $ADMIN->html .= $SKIN->start_form( array( 1 => array( 'code'  , 'doeditsub'  ),
  419.                                                   2 => array( 'act'   , 'forum'  ),
  420.                                                   3 => array( 'f'     , $IN['f'] ),
  421.                                             ) );
  422.         
  423.         //+-------------------------------
  424.         
  425.         $SKIN->td_header[] = array( " "  , "40%" );
  426.         $SKIN->td_header[] = array( " "  , "60%" );
  427.         
  428.         //+-------------------------------
  429.         
  430.         $ADMIN->html .= $SKIN->start_table( "Basic Settings" );
  431.         
  432.         $ADMIN->html .= $SKIN->add_td_row( array( "<b>Add to which parent?</b><br>" ,
  433.                                                   $SKIN->form_dropdown("CATEGORY", $cats)
  434.                                          )      );
  435.                                          
  436.         $ADMIN->html .= $SKIN->end_table();
  437.         
  438.         //+-------------------------------
  439.         
  440.         $SKIN->td_header[] = array( " "  , "40%" );
  441.         $SKIN->td_header[] = array( " "  , "60%" );
  442.         
  443.         $ADMIN->html .= $SKIN->start_table( "Forum Settings" );
  444.         
  445.         $ADMIN->html .= $SKIN->add_td_row( array( "<b>Forum Name</b>" ,
  446.                                                   $SKIN->form_input("name", $forum['name'])
  447.                                          )      );
  448.                                          
  449.         $ADMIN->html .= $SKIN->add_td_row( array( "<b>Forum Description</b>" ,
  450.                                                   $SKIN->form_textarea("desc", $forum['description'])
  451.                                          )      );
  452.                                          
  453.         //+-------------------------------
  454.         
  455.         $ADMIN->html .= $SKIN->end_form("Edit this forum");
  456.                                          
  457.         $ADMIN->html .= $SKIN->end_table();
  458.         
  459.         $ADMIN->output();
  460.             
  461.             
  462.     }
  463.     
  464.     function doeditsub() {
  465.         global $IN, $root_path, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP, $HTTP_POST_VARS;
  466.         
  467.         $IN['FORUM_NAME'] = trim($IN['name']);
  468.         
  469.         if ($IN['FORUM_NAME'] == "")
  470.         {
  471.             $ADMIN->error("You must enter a forum title");
  472.         }
  473.         
  474.         if ($IN['f'] == "")
  475.         {
  476.             $ADMIN->error("No forum id was chosen, please go back and try again");
  477.         }
  478.         
  479.         // Get the new forum id. We could use auto_incrememnt, but we need the ID to use as the default
  480.         // forum position...
  481.         
  482.         $db_string = $DB->compile_db_update_string( array (
  483.                                                             'name'             => $IN['FORUM_NAME'],
  484.                                                             'description'      => str_replace( "\n", "<br>", stripslashes($HTTP_POST_VARS['desc']) ),
  485.                                                             'category'         => $IN['CATEGORY'],
  486.                                                             'subwrap'          => 1,
  487.                                                             
  488.                                                   )       );
  489.                                                   
  490.         $DB->query("UPDATE ibf_forums SET $db_string WHERE id='".$IN['f']."'");
  491.         
  492.         $ADMIN->done_screen("Forum Edited", "Forum Control", "act=cat" );
  493.         
  494.     }
  495.     
  496.     //+---------------------------------------------------------------------------------
  497.     //
  498.     // Show forum rules
  499.     //
  500.     //+---------------------------------------------------------------------------------
  501.     
  502.     function show_rules() {
  503.         global $IN, $root_path, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP;
  504.         
  505.         if ($IN['f'] == "")
  506.         {
  507.             $ADMIN->error("Could not determine the forum ID to empty.");
  508.         }
  509.         
  510.         $DB->query("SELECT id, name, show_rules FROM ibf_forums WHERE id='".$IN['f']."'");
  511.         
  512.         //+-------------------------------
  513.         // Make sure we have a legal forum
  514.         //+-------------------------------
  515.         
  516.         if ( !$DB->get_num_rows() )
  517.         {
  518.             $ADMIN->error("Could not resolve that forum ID");
  519.         }
  520.         
  521.         $forum = $DB->fetch_row();
  522.         
  523.         //+-------------------------------
  524.         
  525.         $DB->query("SELECT * FROM ibf_rules WHERE fid='".$forum['id']."'");
  526.         
  527.         $rules = $DB->fetch_row();
  528.         
  529.         //+-------------------------------
  530.         
  531.         $ADMIN->page_title = "Forum Rules";
  532.         $ADMIN->page_detail  = "You may edit, add, remove or change the state of the forum rules display";
  533.         
  534.         $ADMIN->html .= $SKIN->start_form( array( 1 => array( 'code'  , 'dorules'),
  535.                                                   2 => array( 'act'   , 'forum'  ),
  536.                                                   3 => array( 'f'     , $IN['f'] ),
  537.                                             ) );
  538.         
  539.         
  540.         $SKIN->td_header[] = array( " "   , "40%" );
  541.         $SKIN->td_header[] = array( " "   , "60%" );
  542.         
  543.         $ADMIN->html .= $SKIN->start_table( "Forum Rules set up" );
  544.         
  545.         $ADMIN->html .= $SKIN->add_td_row( array( "<b>Show these rules?</b>" ,
  546.                                                   $SKIN->form_yes_no("show_rules", $forum['show_rules'] )
  547.                                          )      );
  548.                                          
  549.         $ADMIN->html .= $SKIN->add_td_row( array( "<b>Display method:</b>" ,
  550.                                                   $SKIN->form_dropdown( "show_all",
  551.                                                                         array( 
  552.                                                                                 0 => array( '0' , 'Show Link Only' ),
  553.                                                                                 1 => array( '1' , 'Show full text' )
  554.                                                                              ),
  555.                                                                           $rules['show_all']
  556.                                                                         )
  557.                                          )      );
  558.                                          
  559.         $ADMIN->html .= $SKIN->add_td_row( array( "<b>Rules Title</b>" ,
  560.                                                   $SKIN->form_input("title", stripslashes($rules['title']))
  561.                                          )      );
  562.                                          
  563.         $ADMIN->html .= $SKIN->add_td_row( array( "<b>Rules Text</b><br>(HTML Editing Mode)" ,
  564.                                                   $SKIN->form_textarea( "body", stripslashes($rules['body']), 65, 20 )
  565.                                          )      );
  566.                                          
  567.         $ADMIN->html .= $SKIN->end_form("Edit forum rules");
  568.                                          
  569.         $ADMIN->html .= $SKIN->end_table();
  570.         
  571.         $ADMIN->output();
  572.         
  573.     }
  574.     
  575.     
  576.     function do_rules() {
  577.         global $IN, $root_path, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP, $HTTP_POST_VARS;
  578.         
  579.         if ($IN['f'] == "")
  580.         {
  581.             $ADMIN->error("Could not determine the forum ID to empty.");
  582.         }
  583.         
  584.         $rules = array( 
  585.                         'title'    => stripslashes($HTTP_POST_VARS['title']),
  586.                         'body'     => stripslashes($HTTP_POST_VARS['body']),
  587.                         'updated'  => time(),
  588.                         'show_all' => $IN['show_all']
  589.                       );
  590.                       
  591.         // Update the forum first..
  592.         
  593.         $DB->query("UPDATE ibf_forums SET show_rules='".$IN['show_rules']."' WHERE id='".$IN['f']."'");
  594.         
  595.         // Check for existing rules..
  596.         
  597.         $DB->query("SELECT fid FROM ibf_rules WHERE fid='".$IN['f']."'");
  598.         
  599.         if ( $DB->get_num_rows() )
  600.         {
  601.             $string = $DB->compile_db_update_string( $rules );
  602.             
  603.             $DB->query("UPDATE ibf_rules SET $string WHERE fid='".$IN['f']."'");
  604.             
  605.         }
  606.         else
  607.         {
  608.             $rules['fid'] = $IN['f'];
  609.             
  610.             $string = $DB->compile_db_insert_string( $rules );
  611.             
  612.             $DB->query("INSERT INTO ibf_rules (" .$string['FIELD_NAMES']. ") VALUES (". $string['FIELD_VALUES'] .")");
  613.             
  614.         }
  615.         
  616.         $ADMIN->done_screen("Forum Rules Updated", "Forum Control", "act=cat" );
  617.         
  618.     }
  619.     
  620.     //+---------------------------------------------------------------------------------
  621.     //
  622.     // RECOUNT FORUM: Recounts topics and posts
  623.     //
  624.     //+---------------------------------------------------------------------------------
  625.     
  626.     function recount() {
  627.         global $IN, $root_path, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP;
  628.         
  629.         if ($IN['f'] == "")
  630.         {
  631.             $ADMIN->error("Could not determine the forum ID to resync.");
  632.         }
  633.         
  634.         // Get the topics..
  635.         
  636.         $DB->query("SELECT COUNT(tid) as count FROM ibf_topics WHERE approved=1 and forum_id='".$IN['f']."'");
  637.         $topics = $DB->fetch_row();
  638.         
  639.         // Get the posts..
  640.         
  641.         $DB->query("SELECT COUNT(pid) as count FROM ibf_posts WHERE queued <> 1 and forum_id='".$IN['f']."'");
  642.         $posts = $DB->fetch_row();
  643.         
  644.         // Get the forum last poster..
  645.         
  646.         $DB->query("SELECT tid, title, last_poster_id, last_poster_name, last_post FROM ibf_topics WHERE approved=1 and forum_id='".$IN['f']."' ORDER BY last_post DESC LIMIT 0,1");
  647.         $last_post = $DB->fetch_row();
  648.         
  649.         // Reset this forums stats
  650.         
  651.         $postc = $posts['count'] - $topics['count'];
  652.         
  653.         if ($postc < 0)
  654.         {
  655.             $postc = 0;
  656.         }
  657.         
  658.         $db_string = $DB->compile_db_update_string( array (
  659.                                                              'last_poster_id'   => $last_post['last_poster_id'],
  660.                                                              'last_poster_name' => $last_post['last_poster_name'],
  661.                                                              'last_post'        => $last_post['last_post'],
  662.                                                              'last_title'       => $last_post['title'],
  663.                                                              'last_id'          => $last_post['tid'],
  664.                                                              'topics'           => $topics['count'],
  665.                                                              'posts'            => $postc
  666.                                                  )        );
  667.                                                  
  668.         $DB->query("UPDATE ibf_forums SET $db_string WHERE id='".$IN['f']."'");
  669.         
  670.         
  671.         $ADMIN->done_screen("Forum Resynchronised", "Forum Control", "act=cat" );
  672.         
  673.     }
  674.     
  675.     //+---------------------------------------------------------------------------------
  676.     //
  677.     // EMPTY FORUM: Removes all topics and posts, etc.
  678.     //
  679.     //+---------------------------------------------------------------------------------
  680.     
  681.     function empty_form() {
  682.         global $IN, $root_path, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP;
  683.         
  684.         $form_array = array();
  685.         
  686.         if ($IN['f'] == "")
  687.         {
  688.             $ADMIN->error("Could not determine the forum ID to empty.");
  689.         }
  690.         
  691.         $DB->query("SELECT id, name FROM ibf_forums WHERE id='".$IN['f']."'");
  692.         
  693.         //+-------------------------------
  694.         // Make sure we have a legal forum
  695.         //+-------------------------------
  696.         
  697.         if ( !$DB->get_num_rows() )
  698.         {
  699.             $ADMIN->error("Could not resolve that forum ID");
  700.         }
  701.         
  702.         $forum = $DB->fetch_row();
  703.         
  704.         //+-------------------------------
  705.         
  706.         $ADMIN->page_title = "Empty Forum '{$forum['name']}'";
  707.         
  708.         $ADMIN->page_detail = "This WILL DELETE ALL TOPICS, POSTS AND POLLS.<br>The forum itself will not be deleted - please ensure you wish to carry out this action before continuing.";
  709.         
  710.         //+-------------------------------
  711.         
  712.         $ADMIN->html .= $SKIN->start_form( array( 1 => array( 'code'  , 'doempty'),
  713.                                                   2 => array( 'act'   , 'forum'     ),
  714.                                                   3 => array( 'f'     , $IN['f']  ),
  715.                                             ) );
  716.         
  717.         //+-------------------------------
  718.         
  719.         $SKIN->td_header[] = array( " "  , "40%" );
  720.         $SKIN->td_header[] = array( " "  , "60%" );
  721.         
  722.         //+-------------------------------
  723.         
  724.         $ADMIN->html .= $SKIN->start_table( "Empty Forum '{$forum['name']}" );
  725.         
  726.         $ADMIN->html .= $SKIN->add_td_row( array( "<b>Forum to empty: </b>" , $forum['name'] )      );
  727.                                          
  728.         $ADMIN->html .= $SKIN->end_form("Empty this forum");
  729.                                          
  730.         $ADMIN->html .= $SKIN->end_table();
  731.         
  732.         $ADMIN->output();
  733.         
  734.         
  735.     }
  736.     
  737.     //+---------------------------------------------------------------------------------
  738.     
  739.     function do_empty() {
  740.         global $IN, $root_path, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP;
  741.         
  742.         if ($IN['f'] == "")
  743.         {
  744.             $ADMIN->error("Could not determine the source forum ID.");
  745.         }
  746.         
  747.         // Check to make sure its a valid forum.
  748.         
  749.         $DB->query("SELECT id, posts, topics FROM ibf_forums WHERE id='".$IN['f']."'");
  750.         
  751.         if ( ! $forum = $DB->fetch_row() )
  752.         {
  753.             $ADMIN->error("Could not get the forum details for the forum to empty");
  754.         }
  755.         
  756.         // Delete topics...
  757.         
  758.         $DB->query("DELETE FROM ibf_topics WHERE forum_id='".$IN['f']."'");
  759.         
  760.         // Move posts...
  761.         
  762.         $DB->query("DELETE FROM ibf_posts WHERE forum_id='".$IN['f']."'");
  763.         
  764.         // Move polls...
  765.         
  766.         $DB->query("DELETE FROM ibf_polls WHERE forum_id='".$IN['f']."'");
  767.         
  768.         // Move voters...
  769.         
  770.         $DB->query("DELETE FROM ibf_voters WHERE forum_id='".$IN['f']."'");
  771.         
  772.         // Clean up the stats
  773.         
  774.         $DB->query("UPDATE ibf_forums SET posts='0', topics='0', last_post='', last_poster_id='', last_poster_name='', last_title='', last_id='' WHERE id='".$IN['f']."'");
  775.         
  776.         $DB->query("UPDATE ibf_stats SET TOTAL_TOPICS=TOTAL_TOPICS-".$forum['topics'].", TOTAL_REPLIES=TOTAL_REPLIES-".$forum['posts']);
  777.         
  778.         $ADMIN->done_screen("Forum Emptied", "Forum Control", "act=cat" );
  779.         
  780.     }
  781.     
  782.     
  783.     //+---------------------------------------------------------------------------------
  784.     //
  785.     // RE-ORDER CATEGORY
  786.     //
  787.     //+---------------------------------------------------------------------------------
  788.     
  789.     function reorder_form() {
  790.         global $IN, $root_path, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP;
  791.         
  792.         $ADMIN->page_title = "Forum Re-Order";
  793.         $ADMIN->page_detail  = "To re-order the forums, simply choose the position number from the drop down box next to each forum title, when you are satisfied with the ordering, simply hit the submit button at the bottom of the form";
  794.         
  795.         $ADMIN->html .= $SKIN->start_form( array( 1 => array( 'code'  , 'doreorder'),
  796.                                                   2 => array( 'act'   , 'forum'     ),
  797.                                             ) );
  798.         
  799.         
  800.         $SKIN->td_header[] = array( " "       , "10%" );
  801.         $SKIN->td_header[] = array( "Forum Name"   , "60%" );
  802.         $SKIN->td_header[] = array( "Posts"        , "15%" );
  803.         $SKIN->td_header[] = array( "Topics"       , "15%" );
  804.         
  805.         $ADMIN->html .= $SKIN->start_table( "Your Categories and Forums" );
  806.         
  807.         $cats        = array();
  808.         $forums       = array();
  809.         $forum_in_cat = array();
  810.         $children = array();
  811.         
  812.         $DB->query("SELECT * from ibf_categories WHERE id > 0 ORDER BY position ASC");
  813.         while ($r = $DB->fetch_row())
  814.         {
  815.             $cats[$r['id']] = $r;
  816.         }
  817.         
  818.         $DB->query("SELECT * from ibf_forums ORDER BY position ASC");
  819.         while ($r = $DB->fetch_row())
  820.         {
  821.             
  822.             if ($r['parent_id'] > 0)
  823.             {
  824.                 $children[ $r['parent_id'] ][] = $r;
  825.             }
  826.             else
  827.             {
  828.                 $forums[] = $r;
  829.                 $forum_in_cat[ $r['category'] ]++;
  830.             }
  831.             
  832.         }
  833.         
  834.         $i = 1;
  835.         
  836.         $last_cat_id = -1;
  837.         
  838.         foreach ($cats as $c)
  839.         {
  840.             
  841.             $ADMIN->html .= $SKIN->add_td_row( array(  ' ',
  842.                                                        $c['name'],
  843.                                                        ' ',
  844.                                                        ' ',
  845.                                              ), 'catrow'     );
  846.             $last_cat_id = $c['id'];
  847.             
  848.             
  849.             foreach($forums as $r)
  850.             {    
  851.             
  852.                 if ($r['category'] == $last_cat_id)
  853.                 {
  854.                 
  855.                     
  856.                     $form_array = array();
  857.                 
  858.                     for ($c = 1 ; $c <= $forum_in_cat[ $r['category'] ] ; $c++ )
  859.                     {
  860.                         $i++;
  861.                         
  862.                         $form_array[] = array( $c, $c );
  863.                     }
  864.                     
  865.                     if ($r['subwrap'] == 1)
  866.                     {
  867.                     
  868.                         $ADMIN->html .= $SKIN->add_td_row( array(  $SKIN->form_dropdown( 'POS_'.$r['id'], $form_array, $r['position'] ),
  869.                                                                    $r['name'],
  870.                                                                    ' ',
  871.                                                                    ' ',
  872.                                                          ), 'catrow2'     );
  873.                     }
  874.                     else
  875.                     {
  876.                     
  877.                 
  878.                         $ADMIN->html .= $SKIN->add_td_row( array(
  879.                                                                    $SKIN->form_dropdown( 'POS_'.$r['id'], $form_array, $r['position'] ),
  880.                                                                    "<b>".$r['name']."</b><br>".$r['description'],
  881.                                                                    $r['posts'],
  882.                                                                    $r['topics'],
  883.                                                          )      );
  884.                     }
  885.                     
  886.                                                      
  887.                     if ( ( isset($children[ $r['id'] ]) ) and ( count ($children[ $r['id'] ]) > 0 ) )
  888.                     {
  889.                         foreach($children[ $r['id'] ] as $idx => $rd)
  890.                         {
  891.                             $form_array = array();
  892.                     
  893.                             for ($c = 1 ; $c <= count($children[ $r['id'] ]) ; $c++ )
  894.                             {
  895.                                 $i++;
  896.                                 
  897.                                 $form_array[] = array( $c, $c );
  898.                             }
  899.                             
  900.                         
  901.                             $ADMIN->html .= $SKIN->add_td_row( array(
  902.                                                                        $SKIN->form_dropdown( 'POS_'.$rd['id'], $form_array, $rd['position'] ),
  903.                                                                        "<b>".$rd['name']."</b><br>".$rd['description'],
  904.                                                                        $rd['posts'],
  905.                                                                        $rd['topics'],
  906.                                                              ), 'subforum'      );
  907.                         }
  908.                     }                     
  909.                 }
  910.             }
  911.         }
  912.         
  913.         $ADMIN->html .= $SKIN->end_form("Adjust Forum Ordering");
  914.         
  915.         $ADMIN->html .= $SKIN->end_table();
  916.         
  917.         $ADMIN->output();
  918.         
  919.     }
  920.     
  921.     //+---------------------------------------------------------------------------------
  922.     
  923.     function do_reorder() {
  924.         global $IN, $root_path, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP;
  925.         
  926.         $cat_query = $DB->query("SELECT id from ibf_forums");
  927.         
  928.         while ( $r = $DB->fetch_row($cat_query) )
  929.         {
  930.             $order_query = $DB->query("UPDATE ibf_forums SET position='".$IN[ 'POS_' . $r['id'] ]."' WHERE id='".$r['id']."'");
  931.         }
  932.         
  933.         $ADMIN->done_screen("Forum Ordering Adjusted", "Forum Control", "act=cat" );
  934.         
  935.     }
  936.     
  937.     
  938.     //+---------------------------------------------------------------------------------
  939.     //
  940.     // REMOVE FORUM
  941.     //
  942.     //+---------------------------------------------------------------------------------
  943.     
  944.     function delete_form() {
  945.         global $IN, $root_path, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP;
  946.         
  947.         $form_array = array();
  948.         
  949.         if ($IN['f'] == "")
  950.         {
  951.             $ADMIN->error("Could not determine the forum ID to delete.");
  952.         }
  953.         
  954.         $DB->query("SELECT id, name FROM ibf_forums ORDER BY position");
  955.         
  956.         //+-------------------------------
  957.         // Make sure we have more than 1
  958.         // forum..
  959.         //+-------------------------------
  960.         
  961.         if ($DB->get_num_rows() < 2)
  962.         {
  963.             $ADMIN->error("Can not remove this forum, please create another before attempting to remove this one");
  964.         }
  965.         
  966.         while ( $r = $DB->fetch_row() )
  967.         {
  968.             if ($r['id'] == $IN['f'])
  969.             {
  970.                 $name = $r['name'];
  971.                 continue;
  972.             }
  973.             
  974.             $form_array[] = array( $r['id'] , $r['name'] );
  975.         }
  976.         
  977.         //+-------------------------------
  978.         
  979.         $ADMIN->page_title = "Removing forum '$name'";
  980.         
  981.         $ADMIN->page_detail = "Before we remove this forum, we need to determine what to do with any topics and posts you may have left in this category.";
  982.         
  983.         //+-------------------------------
  984.         
  985.         $ADMIN->html .= $SKIN->start_form( array( 1 => array( 'code'  , 'dodelete'),
  986.                                                   2 => array( 'act'   , 'forum'     ),
  987.                                                   3 => array( 'f'     , $IN['f']  ),
  988.                                             ) );
  989.         
  990.         //+-------------------------------
  991.         
  992.         $SKIN->td_header[] = array( " "  , "40%" );
  993.         $SKIN->td_header[] = array( " "  , "60%" );
  994.         
  995.         //+-------------------------------
  996.         
  997.         $ADMIN->html .= $SKIN->start_table( "Required" );
  998.         
  999.         $ADMIN->html .= $SKIN->add_td_row( array( "<b>Forum to remove: </b>" , $name )      );
  1000.                                          
  1001.         $ADMIN->html .= $SKIN->add_td_row( array( "<b>Move all <i>existing topics and posts in this forum</i> to which forum?</b>" ,
  1002.                                                   $SKIN->form_dropdown( "MOVE_ID", $form_array )
  1003.                                          )      );
  1004.                                          
  1005.         $ADMIN->html .= $SKIN->end_form("Move topics and delete this forum");
  1006.                                          
  1007.         $ADMIN->html .= $SKIN->end_table();
  1008.         
  1009.         $ADMIN->output();
  1010.         
  1011.         
  1012.     }
  1013.     
  1014.     //+---------------------------------------------------------------------------------
  1015.     
  1016.     function do_delete() {
  1017.         global $IN, $root_path, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP;
  1018.         
  1019.         if ($IN['f'] == "")
  1020.         {
  1021.             $ADMIN->error("Could not determine the source forum ID.");
  1022.         }
  1023.         
  1024.         if ($IN['MOVE_ID'] == "")
  1025.         {
  1026.             $ADMIN->error("Could not determine the destination forum ID.");
  1027.         }
  1028.         
  1029.         // Move topics...
  1030.         
  1031.         $DB->query("UPDATE ibf_topics SET forum_id='".$IN['MOVE_ID']."' WHERE forum_id='".$IN['f']."'");
  1032.         
  1033.         // Move posts...
  1034.         
  1035.         $DB->query("UPDATE ibf_posts SET forum_id='".$IN['MOVE_ID']."' WHERE forum_id='".$IN['f']."'");
  1036.         
  1037.         // Move polls...
  1038.         
  1039.         $DB->query("UPDATE ibf_polls SET forum_id='".$IN['MOVE_ID']."' WHERE forum_id='".$IN['f']."'");
  1040.         
  1041.         // Move voters...
  1042.         
  1043.         $DB->query("UPDATE ibf_voters SET forum_id='".$IN['MOVE_ID']."' WHERE forum_id='".$IN['f']."'");
  1044.         
  1045.         // Delete the forum
  1046.         
  1047.         $DB->query("DELETE FROM ibf_forums WHERE id='".$IN['f']."'");
  1048.         
  1049.         // Delete forum rules, if any..
  1050.         
  1051.         $DB->query("DELETE FROM ibf_rules WHERE fid='".$IN['f']."'");
  1052.         
  1053.         $ADMIN->done_screen("Forum Removed", "Forum Control", "act=cat" );
  1054.         
  1055.     }
  1056.     
  1057.     
  1058.     //+---------------------------------------------------------------------------------
  1059.     //
  1060.     // NEW FORUM
  1061.     //
  1062.     //+---------------------------------------------------------------------------------
  1063.     
  1064.     function new_splash() {
  1065.         global $IN, $root_path, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP, $HTTP_GET_VARS;
  1066.         
  1067.         $f_name = "";
  1068.         
  1069.         
  1070.         $ADMIN->page_title = "Add a new Forum";
  1071.         
  1072.         $ADMIN->page_detail = "Please choose how this forum should act.<br><b>A Sub Category forum</b> will allow you to add many forums to this sub category forum - these added forums will remain 'hidden' until the forum link is clicked on.<br><b>A normal forum</b> will act as a normal child of a category.";
  1073.         
  1074.         //+-------------------------------
  1075.         
  1076.         $ADMIN->html .= $SKIN->start_form( array( 1 => array( 'code'  , 'donewsplash'  ),
  1077.                                                   2 => array( 'act'   , 'forum'        ),
  1078.                                             ) );
  1079.         
  1080.         //+-------------------------------
  1081.         
  1082.         $SKIN->td_header[] = array( " "  , "40%" );
  1083.         $SKIN->td_header[] = array( " "  , "60%" );
  1084.         
  1085.         //+-------------------------------
  1086.         
  1087.         $ADMIN->html .= $SKIN->start_table( "Forum Type" );
  1088.         
  1089.                                          
  1090.         $ADMIN->html .= $SKIN->add_td_row( array( "<b>Make this forum: </b>" ,
  1091.                                                   $SKIN->form_dropdown( "forum_type",
  1092.                                                                             array( 
  1093.                                                                                     0 => array( 'n', 'Normal Forum'        ),
  1094.                                                                                     1 => array( 's', 'Sub Category Forum'  ),
  1095.                                                                                  ),
  1096.                                                                           "1"
  1097.                                                                         )
  1098.                                          )      );
  1099.                                          
  1100.         $ADMIN->html .= $SKIN->end_form("Create this forum");
  1101.                                          
  1102.         $ADMIN->html .= $SKIN->end_table();
  1103.         
  1104.         $ADMIN->output();
  1105.             
  1106.             
  1107.     }
  1108.     
  1109.     function donew_splash() {
  1110.         global $IN, $root_path, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP, $HTTP_GET_VARS;
  1111.         
  1112.         if ($IN['forum_type'] == 'n')
  1113.         {
  1114.             $this->new_form();
  1115.         }
  1116.         else
  1117.         {
  1118.             $this->newsub_form();
  1119.         }
  1120.         
  1121.         
  1122.     }
  1123.     
  1124.     //------------------------------------------------------------------------------------------------
  1125.     //------------------------------------------------------------------------------------------------
  1126.     
  1127.     function newsub_form() {
  1128.         global $IN, $root_path, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP, $HTTP_GET_VARS;
  1129.         
  1130.         $f_name = "";
  1131.         
  1132.         if ($HTTP_GET_VARS['name'] != "")
  1133.         {
  1134.             $f_name = stripslashes(urldecode($HTTP_GET_VARS['name']));
  1135.         }
  1136.         
  1137.         $cats = array();
  1138.         
  1139.         $last_cat_id = -1;
  1140.         
  1141.         $DB->query("SELECT * from ibf_categories WHERE id > 0 ORDER BY position");
  1142.         
  1143.         while ( $r = $DB->fetch_row() )
  1144.         {
  1145.             $cats[] = array( $r['id'] , "Category: ".$r['name'] );
  1146.         }
  1147.             
  1148.             
  1149.         
  1150.         $ADMIN->page_title = "Add a new Sub Category Forum";
  1151.         
  1152.         $ADMIN->page_detail = "This section will allow you to add a new sub category forum.";
  1153.         
  1154.         //+-------------------------------
  1155.         
  1156.         $ADMIN->html .= $SKIN->start_form( array( 1 => array( 'code'  , 'donewsub'  ),
  1157.                                                   2 => array( 'act'   , 'forum'  ),
  1158.                                             ) );
  1159.         
  1160.         //+-------------------------------
  1161.         
  1162.         $SKIN->td_header[] = array( " "  , "40%" );
  1163.         $SKIN->td_header[] = array( " "  , "60%" );
  1164.         
  1165.         //+-------------------------------
  1166.         
  1167.         $ADMIN->html .= $SKIN->start_table( "Basic Settings" );
  1168.         
  1169.         $ADMIN->html .= $SKIN->add_td_row( array( "<b>Add to which parent?</b><br>" ,
  1170.                                                   $SKIN->form_dropdown("CATEGORY", $cats)
  1171.                                          )      );
  1172.                                          
  1173.         $ADMIN->html .= $SKIN->end_table();
  1174.         
  1175.         //+-------------------------------
  1176.         
  1177.         $SKIN->td_header[] = array( " "  , "40%" );
  1178.         $SKIN->td_header[] = array( " "  , "60%" );
  1179.         
  1180.         $ADMIN->html .= $SKIN->start_table( "Forum Settings" );
  1181.         
  1182.         $ADMIN->html .= $SKIN->add_td_row( array( "<b>Forum Name</b>" ,
  1183.                                                   $SKIN->form_input("name", $f_name)
  1184.                                          )      );
  1185.                                          
  1186.         $ADMIN->html .= $SKIN->add_td_row( array( "<b>Forum Description</b>You may use HTML" ,
  1187.                                                   $SKIN->form_textarea("desc")
  1188.                                          )      );
  1189.                                          
  1190.         //+-------------------------------
  1191.         
  1192.         $ADMIN->html .= $SKIN->end_form("Create this forum");
  1193.                                          
  1194.         $ADMIN->html .= $SKIN->end_table();
  1195.         
  1196.         $ADMIN->output();
  1197.             
  1198.             
  1199.     }
  1200.  
  1201.     //------------------------------------------------------------------------------------------------
  1202.     //------------------------------------------------------------------------------------------------
  1203.     
  1204.     function new_form() {
  1205.         global $IN, $root_path, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP, $HTTP_GET_VARS;
  1206.         
  1207.         $f_name = "";
  1208.         
  1209.         if ($HTTP_GET_VARS['name'] != "")
  1210.         {
  1211.             $f_name = stripslashes(urldecode($HTTP_GET_VARS['name']));
  1212.         }
  1213.         
  1214.         $cats = array();
  1215.         $seen = array();
  1216.         
  1217.         $last_cat_id = -1;
  1218.         
  1219.         $DB->query("SELECT c.id, c.name, f.id as forum_id, f.subwrap, f.name as forum_name, f.subwrap, f.parent_id, f.category FROM ibf_categories c, ibf_forums f WHERE c.id > 0 ORDER BY c.position, f.position");
  1220.         
  1221.         if ( $DB->get_num_rows() )
  1222.         {
  1223.         
  1224.             while ( $r = $DB->fetch_row() )
  1225.             {
  1226.             
  1227.                 if ($seen[$r['id']] == 1 and $r['subwrap'] != 1)
  1228.                 {
  1229.                     continue;
  1230.                 }
  1231.                     
  1232.                 if ($last_cat_id != $r['id'])
  1233.                 {
  1234.                     $cats[] = array( "c_".$r['id'] , "Category: ".$r['name'] );
  1235.                     
  1236.                     $seen[$r['id']] = 1;
  1237.                     
  1238.                     $last_cat_id = $r['id'];
  1239.                     
  1240.                 }
  1241.                 
  1242.                 if ($r['parent_id'] > 0)
  1243.                 {
  1244.                     continue;
  1245.                 }
  1246.                 
  1247.                 if ($r['subwrap'] != 1)
  1248.                 {
  1249.                     continue;
  1250.                 }
  1251.                 
  1252.                 if ($r['category'] == $r['id'])
  1253.                 {
  1254.                 
  1255.                     $cats[] = array( "f_".$r['forum_id'], "Sub Category Forum: ".$r['forum_name'] );
  1256.                 }
  1257.                 
  1258.             }
  1259.         
  1260.         }
  1261.         else
  1262.         {
  1263.             // No forums, get cats only..
  1264.             
  1265.             $DB->query("SELECT * from ibf_categories WHERE id > 0");
  1266.             
  1267.             while ($r = $DB->fetch_row())
  1268.             {
  1269.                 $cats[] = array( "c_".$r['id'] , "Category: ".$r['name'] );
  1270.             }
  1271.             
  1272.         }
  1273.         
  1274.         $ADMIN->page_title = "Add a new Forum";
  1275.         
  1276.         $ADMIN->page_detail = "This section will allow you to add a new forum to an existing category. Please ensure you select the correct category to insert
  1277.                                the new forum into. If you do make a mistake, clicking on \"Edit Settings\" will allow you to make any changes after the forum has
  1278.                                been created.";
  1279.         
  1280.         //+-------------------------------
  1281.         
  1282.         $ADMIN->html .= $SKIN->start_form( array( 1 => array( 'code'  , 'donew'  ),
  1283.                                                   2 => array( 'act'   , 'forum'  ),
  1284.                                             ) );
  1285.         
  1286.         //+-------------------------------
  1287.         
  1288.         $SKIN->td_header[] = array( " "  , "40%" );
  1289.         $SKIN->td_header[] = array( " "  , "60%" );
  1290.         
  1291.         //+-------------------------------
  1292.         
  1293.         $ADMIN->html .= $SKIN->start_table( "Basic Settings" );
  1294.         
  1295.         $ADMIN->html .= $SKIN->add_td_row( array( "<b>Add to which parent?</b><br>" ,
  1296.                                                   $SKIN->form_dropdown("CATEGORY", $cats)
  1297.                                          )      );
  1298.                                          
  1299.         $ADMIN->html .= $SKIN->add_td_row( array( "<b>Forum State</b>" ,
  1300.                                                   $SKIN->form_dropdown( "FORUM_STATUS",
  1301.                                                                             array( 
  1302.                                                                                     0 => array( 1, 'Active' ),
  1303.                                                                                     1 => array( 0, 'Read Only Archive'  ),
  1304.                                                                                  ),
  1305.                                                                           "1"
  1306.                                                                         )
  1307.                                          )      );
  1308.                                          
  1309.         $ADMIN->html .= $SKIN->end_table();
  1310.         
  1311.         //+-------------------------------
  1312.         
  1313.         $SKIN->td_header[] = array( " "  , "40%" );
  1314.         $SKIN->td_header[] = array( " "  , "60%" );
  1315.         
  1316.         $ADMIN->html .= $SKIN->start_table( "Forum Settings" );
  1317.         
  1318.         $ADMIN->html .= $SKIN->add_td_row( array( "<b>Forum Name</b>" ,
  1319.                                                   $SKIN->form_input("FORUM_NAME", $f_name)
  1320.                                          )      );
  1321.                                          
  1322.         $ADMIN->html .= $SKIN->add_td_row( array( "<b>Forum Description</b><br>You may use HTML - linebreaks are converted 'Auto-Magically'" ,
  1323.                                                   $SKIN->form_textarea("FORUM_DESC")
  1324.                                          )      );
  1325.                                          
  1326.         $ADMIN->html .= $SKIN->add_td_row( array( "<b>Allow HTML to be posted?</b>" ,
  1327.                                                   $SKIN->form_yes_no("FORUM_HTML", 0 )
  1328.                                          )      );
  1329.                                          
  1330.         $ADMIN->html .= $SKIN->add_td_row( array( "<b>Allow IBF CODE to be posted?</b>" ,
  1331.                                                   $SKIN->form_yes_no("FORUM_IBC", 1 )
  1332.                                          )      );
  1333.                                          
  1334.         //-----------
  1335.                                          
  1336.         $ADMIN->html .= $SKIN->add_td_row( array( "<b>Allow Polls in this forum (when allowed)?</b>" ,
  1337.                                                   $SKIN->form_yes_no("allow_poll", 1 )
  1338.                                          )      );
  1339.         
  1340.         $ADMIN->html .= $SKIN->add_td_row( array( "<b>Allow votes to bump a topic?</b>" ,
  1341.                                                   $SKIN->form_yes_no("allow_pollbump", 0 )
  1342.                                          )      );
  1343.         
  1344.         $ADMIN->html .= $SKIN->add_td_row( array( "<b>Posts in this forum increase member post count?</b>" ,
  1345.                                                   $SKIN->form_yes_no("inc_postcount", 1 )
  1346.                                          )      );
  1347.                                          
  1348.         //-----------
  1349.                                          
  1350.         $ADMIN->html .= $SKIN->add_td_row( array( "<b>Allow post uploads?</b>" ,
  1351.                                                   $SKIN->form_yes_no("ALLOW_ATTACH", 0 )
  1352.                                          )      );
  1353.         
  1354.         $ADMIN->html .= $SKIN->add_td_row( array( "<b>Preview all posts?</b><br>(Requires a moderator to manually add posts to the forum)" ,
  1355.                                                   $SKIN->form_yes_no("MODERATE", 0 )
  1356.                                          )      );
  1357.                                          
  1358.         $ADMIN->html .= $SKIN->add_td_row( array( "<b>Require password access?<br>Enter the password here</b><br>(Leave this box empty if you do not require this)" ,
  1359.                                                   $SKIN->form_input("FORUM_PROTECT")
  1360.                                          )      );
  1361.                                          
  1362.         $ADMIN->html .= $SKIN->add_td_row( array( "<b>Default date cut off for topic display</b>" ,
  1363.                                                   $SKIN->form_dropdown( "PRUNE_DAYS",
  1364.                                                                             array( 
  1365.                                                                                     0 => array( 1, 'Today' ),
  1366.                                                                                     1 => array( 5, 'Last 5 days'  ),
  1367.                                                                                     2 => array( 7, 'Last 7 days'  ),
  1368.                                                                                     3 => array( 10, 'Last 10 days' ),
  1369.                                                                                     4 => array( 15, 'Last 15 days' ),
  1370.                                                                                     5 => array( 20, 'Last 20 days' ),
  1371.                                                                                     6 => array( 25, 'Last 25 days' ),
  1372.                                                                                     7 => array( 30, 'Last 30 days' ),
  1373.                                                                                     8 => array( 60, 'Last 60 days' ),
  1374.                                                                                     9 => array( 90, 'Last 90 days' ),
  1375.                                                                                     10=> array( 100,'Show All'     ),
  1376.                                                                                  ),
  1377.                                                                           "30"
  1378.                                                                         )
  1379.                                          )      );
  1380.                                          
  1381.         $ADMIN->html .= $SKIN->add_td_row( array( "<b>Default sort key</b>" ,
  1382.                                                   $SKIN->form_dropdown( "SORT_KEY",
  1383.                                                                             array( 
  1384.                                                                                     0 => array( 'last_post', 'Date of the last post' ),
  1385.                                                                                     1 => array( 'title'    , 'Topic Title' ),
  1386.                                                                                     2 => array( 'starter_name', 'Topic Starters Name' ),
  1387.                                                                                     3 => array( 'posts'    , 'Topic Posts' ),
  1388.                                                                                     4 => array( 'views'    , 'Topic Views' ),
  1389.                                                                                     5 => array( 'start_date', 'Date topic started' ),
  1390.                                                                                     6 => array( 'last_poster_name'   , 'Name of the last poster' ),
  1391.                                                                                  ),
  1392.                                                                           "last_post"
  1393.                                                                         )
  1394.                                          )      );
  1395.                                          
  1396.         $ADMIN->html .= $SKIN->add_td_row( array( "<b>Default sort order</b>" ,
  1397.                                                   $SKIN->form_dropdown( "SORT_ORDER",
  1398.                                                                             array( 
  1399.                                                                                     0 => array( 'Z-A', 'Descending (Z - A, 0 - 10)' ),
  1400.                                                                                     1 => array( 'A-Z', 'Ascending (A - Z, 10 - 0)' ),
  1401.                                                                                  ),
  1402.                                                                           "Z-A"
  1403.                                                                         )
  1404.                                          )      );
  1405.                                          
  1406.         $ADMIN->html .= $SKIN->end_table();
  1407.         
  1408.         //+-------------------------------
  1409.         
  1410.         $SKIN->td_header[] = array( " "  , "40%" );
  1411.         $SKIN->td_header[] = array( " "  , "60%" );
  1412.         
  1413.         $ADMIN->html .= $SKIN->start_table( "Forum Access Permissions" );
  1414.         
  1415.         $ADMIN->html .= $SKIN->add_td_row( array( "<b>Forum access permissions</b><br>(Check box for access, uncheck to not allow access)<br>If you deny read access for a member group, they will not see the forum" ,
  1416.                                                   $SKIN->build_group_perms()
  1417.                                          )      );
  1418.         
  1419.         //+-------------------------------
  1420.         
  1421.         $ADMIN->html .= $SKIN->end_form("Create this forum");
  1422.                                          
  1423.         $ADMIN->html .= $SKIN->end_table();
  1424.         
  1425.         $ADMIN->output();
  1426.             
  1427.             
  1428.     }
  1429.  
  1430.  
  1431.     //------------------------------------------------------------------------------------------------
  1432.     //------------------------------------------------------------------------------------------------
  1433.     
  1434.     function do_new() {
  1435.         global $IN, $root_path, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP, $HTTP_POST_VARS;
  1436.         
  1437.         $IN['FORUM_NAME'] = trim($IN['FORUM_NAME']);
  1438.         
  1439.         if ($IN['FORUM_NAME'] == "")
  1440.         {
  1441.             $ADMIN->error("You must enter a forum title");
  1442.         }
  1443.         
  1444.         // Get the new forum id. We could use auto_incrememnt, but we need the ID to use as the default
  1445.         // forum position...
  1446.         
  1447.         $DB->query("SELECT MAX(id) as top_forum FROM ibf_forums");
  1448.         $row = $DB->fetch_row();
  1449.         
  1450.         if ($row['top_forum'] < 1) $row['top_forum'] = 0;
  1451.         
  1452.         $row['top_forum']++;
  1453.         
  1454.         $perms = $ADMIN->compile_forum_perms();
  1455.         
  1456.         $cat    = -1;
  1457.         $parent = -1;
  1458.         
  1459.         if ( preg_match( "/^c_(\d+)$/", $IN['CATEGORY'], $match ) )
  1460.         {
  1461.             $cat = $match[1];
  1462.         }
  1463.         else
  1464.         {
  1465.             $parent = preg_replace( "/^f_/", "", $IN['CATEGORY'] );
  1466.             
  1467.             $DB->query("SELECT category FROM ibf_forums WHERE id='$parent'");
  1468.             
  1469.             if ($forum_result = $DB->fetch_row())
  1470.             {
  1471.                 $cat = $forum_result['category'];
  1472.             }
  1473.         }
  1474.         
  1475.         $db_string = $DB->compile_db_insert_string( array (
  1476.                                                             'id'               => $row['top_forum'],
  1477.                                                             'position'         => $row['top_forum'],
  1478.                                                             'topics'           => 0,
  1479.                                                             'posts'            => 0,
  1480.                                                             'last_post'        => "",
  1481.                                                             'last_poster_id'   => "",
  1482.                                                             'last_poster_name' => "",
  1483.                                                             'name'             => $IN['FORUM_NAME'],
  1484.                                                             'description'      => str_replace( "\n", "<br>", stripslashes($HTTP_POST_VARS['FORUM_DESC']) ),
  1485.                                                             'use_ibc'          => $IN['FORUM_IBC'],
  1486.                                                             'use_html'         => $IN['FORUM_HTML'],
  1487.                                                             'status'           => $IN['FORUM_STATUS'],
  1488.                                                             'start_perms'      => $perms['START'],
  1489.                                                             'reply_perms'      => $perms['REPLY'],
  1490.                                                             'read_perms'       => $perms['READ'],
  1491.                                                             'password'         => $IN['FORUM_PROTECT'],
  1492.                                                             'category'         => $cat,
  1493.                                                             'last_id'          => "",
  1494.                                                             'last_title'       => "",
  1495.                                                             'sort_key'         => $IN['SORT_KEY'],
  1496.                                                             'sort_order'       => $IN['SORT_ORDER'],
  1497.                                                             'prune'            => $IN['PRUNE_DAYS'],
  1498.                                                             'show_rules'       => 0,
  1499.                                                             'use_attach'       => $IN['ALLOW_ATTACH'],
  1500.                                                             'preview_posts'    => $IN['MODERATE'],
  1501.                                                             'allow_poll'       => $IN['allow_poll'],
  1502.                                                             'allow_pollbump'   => $IN['allow_pollbump'],
  1503.                                                             'inc_postcount'    => $IN['inc_postcount'],
  1504.                                                             'parent_id'        => $parent
  1505.                                                             
  1506.                                                   )       );
  1507.                                                   
  1508.         $DB->query("INSERT INTO ibf_forums (".$db_string['FIELD_NAMES'].") VALUES (".$db_string['FIELD_VALUES'].")");
  1509.         
  1510.         $ADMIN->done_screen("Forum {$IN['CAT_NAME']} created", "Forum Control", "act=cat" );
  1511.         
  1512.         
  1513.         
  1514.     }
  1515.     
  1516.     //------------------------------------------------------------------------------------------------
  1517.     //------------------------------------------------------------------------------------------------
  1518.     
  1519.     function add_sub() {
  1520.         global $IN, $root_path, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP, $HTTP_POST_VARS;
  1521.         
  1522.         $IN['FORUM_NAME'] = trim($IN['name']);
  1523.         
  1524.         if ($IN['FORUM_NAME'] == "")
  1525.         {
  1526.             $ADMIN->error("You must enter a forum title");
  1527.         }
  1528.         
  1529.         // Get the new forum id. We could use auto_incrememnt, but we need the ID to use as the default
  1530.         // forum position...
  1531.         
  1532.         $DB->query("SELECT MAX(id) as top_forum FROM ibf_forums");
  1533.         $row = $DB->fetch_row();
  1534.         
  1535.         if ($row['top_forum'] < 1) $row['top_forum'] = 0;
  1536.         
  1537.         $row['top_forum']++;
  1538.         
  1539.         $db_string = $DB->compile_db_insert_string( array (
  1540.                                                             'id'               => $row['top_forum'],
  1541.                                                             'position'         => $row['top_forum'],
  1542.                                                             'topics'           => 0,
  1543.                                                             'posts'            => 0,
  1544.                                                             'last_post'        => "",
  1545.                                                             'last_poster_id'   => "",
  1546.                                                             'last_poster_name' => "",
  1547.                                                             'name'             => $IN['FORUM_NAME'],
  1548.                                                             'description'      => str_replace( "\n", "<br>", stripslashes($HTTP_POST_VARS['desc']) ),
  1549.                                                             'use_ibc'          => -1,
  1550.                                                             'use_html'         => -1,
  1551.                                                             'status'           => 1,
  1552.                                                             'start_perms'      => -1,
  1553.                                                             'reply_perms'      => -1,
  1554.                                                             'read_perms'       => -1,
  1555.                                                             'password'         => -1,
  1556.                                                             'category'         => $IN['CATEGORY'],
  1557.                                                             'last_id'          => "",
  1558.                                                             'last_title'       => "",
  1559.                                                             'sort_key'         => -1,
  1560.                                                             'sort_order'       => -1,
  1561.                                                             'prune'            => -1,
  1562.                                                             'show_rules'       => 0,
  1563.                                                             'use_attach'       => -1,
  1564.                                                             'preview_posts'    => -1,
  1565.                                                             'allow_poll'       => -1,
  1566.                                                             'allow_pollbump'   => -1,
  1567.                                                             'inc_postcount'    => -1,
  1568.                                                             'parent_id'        => -1,
  1569.                                                             'subwrap'          => 1,
  1570.                                                             
  1571.                                                   )       );
  1572.                                                   
  1573.         $DB->query("INSERT INTO ibf_forums (".$db_string['FIELD_NAMES'].") VALUES (".$db_string['FIELD_VALUES'].")");
  1574.         
  1575.         $ADMIN->done_screen("Forum {$IN['CAT_NAME']} created", "Forum Control", "act=cat" );
  1576.         
  1577.         
  1578.         
  1579.     }
  1580.  
  1581.  
  1582.  
  1583.     //+---------------------------------------------------------------------------------
  1584.     //
  1585.     // EDIT FORUM
  1586.     //
  1587.     //+---------------------------------------------------------------------------------
  1588.     
  1589.     function edit_form() {
  1590.         global $IN, $root_path, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP;
  1591.         
  1592.         if ($IN['f'] == "")
  1593.         {
  1594.             $ADMIN->error("You didn't choose a forum to edit, duh!");
  1595.         }
  1596.         
  1597.         $cats = array();
  1598.         $seen = array();
  1599.         
  1600.         $last_cat_id = -1;
  1601.         
  1602.         $DB->query("SELECT c.id, c.name, f.subwrap, f.id as forum_id, f.name as forum_name, f.subwrap, f.parent_id, f.category FROM ibf_categories c, ibf_forums f WHERE c.id > 0 ORDER BY c.position, f.position");
  1603.         
  1604.         while ( $r = $DB->fetch_row() )
  1605.         {
  1606.             
  1607.             if ($seen[$r['id']] == 1 and $r['subwrap'] != 1)
  1608.             {
  1609.                 continue;
  1610.             }
  1611.                 
  1612.             if ($last_cat_id != $r['id'])
  1613.             {
  1614.                 $cats[] = array( "c_".$r['id'] , "Category: ".$r['name'] );
  1615.                 
  1616.                 $seen[$r['id']] = 1;
  1617.                 
  1618.                 $last_cat_id = $r['id'];
  1619.                 
  1620.             }
  1621.             
  1622.             if ($r['parent_id'] > 0)
  1623.             {
  1624.                 continue;
  1625.             }
  1626.             
  1627.             if ($r['subwrap'] != 1)
  1628.             {
  1629.                 continue;
  1630.             }
  1631.             
  1632.             if ($r['category'] == $r['id'])
  1633.             {
  1634.             
  1635.                 $cats[] = array( "f_".$r['forum_id'], "Sub Category Forum: ".$r['forum_name'] );
  1636.             }
  1637.             
  1638.         }
  1639.         
  1640.         $DB->query("SELECT * FROM ibf_forums WHERE id='".$IN['f']."'");
  1641.         $forum = $DB->fetch_row();
  1642.         
  1643.         if ($forum['id'] == "")
  1644.         {
  1645.             $ADMIN->error("Could not retrieve the forum data based on ID {$IN['f']}");
  1646.         }
  1647.         
  1648.         //-------------------------------------
  1649.         
  1650.         $real_parent = "";
  1651.         
  1652.         if ($forum['category'] > 0)
  1653.         {
  1654.             $real_parent = 'c_'.$forum['category'];
  1655.         }
  1656.         else
  1657.         {
  1658.             $real_parent = 'f_'.$forum['parent_id'];
  1659.         }
  1660.         
  1661.         //-------------------------------------
  1662.         
  1663.         $ADMIN->page_title = "Edit a Forum";
  1664.         
  1665.         $ADMIN->page_detail = "This section will allow you to edit an existing forum. If you wish to adjust the forum permissions (who has the ability to
  1666.                                start, reply and read topics) click on 'Edit Permissions on the Forums and Categories overview.";
  1667.         
  1668.         //+-------------------------------
  1669.         
  1670.         $ADMIN->html .= $SKIN->start_form( array( 1 => array( 'code'  , 'doedit'  ),
  1671.                                                   2 => array( 'act'   , 'forum'   ),
  1672.                                                   3 => array( 'f'     , $IN['f']  ),
  1673.                                             ) );
  1674.         
  1675.         //+-------------------------------
  1676.         
  1677.         $SKIN->td_header[] = array( " "  , "40%" );
  1678.         $SKIN->td_header[] = array( " "  , "60%" );
  1679.         
  1680.         //+-------------------------------
  1681.         
  1682.         $ADMIN->html .= $SKIN->start_table( "Basic Settings" );
  1683.         
  1684.         $ADMIN->html .= $SKIN->add_td_row( array( "<b>Add to which parent?</b><br>" ,
  1685.                                                   $SKIN->form_dropdown("CATEGORY", $cats, $real_parent)
  1686.                                          )      );
  1687.                                          
  1688.         $ADMIN->html .= $SKIN->add_td_row( array( "<b>Forum State</b>" ,
  1689.                                                   $SKIN->form_dropdown( "FORUM_STATUS",
  1690.                                                                             array( 
  1691.                                                                                     0 => array( 1, 'Active' ),
  1692.                                                                                     1 => array( 0, 'Read Only Archive'  ),
  1693.                                                                                  ),
  1694.                                                                           $forum['status']
  1695.                                                                         )
  1696.                                          )      );
  1697.                                          
  1698.         $ADMIN->html .= $SKIN->end_table();
  1699.         
  1700.         //+-------------------------------
  1701.         
  1702.         $SKIN->td_header[] = array( " "  , "40%" );
  1703.         $SKIN->td_header[] = array( " "  , "60%" );
  1704.         
  1705.         $ADMIN->html .= $SKIN->start_table( "Forum Settings" );
  1706.         
  1707.         $ADMIN->html .= $SKIN->add_td_row( array( "<b>Forum Name</b>" ,
  1708.                                                   $SKIN->form_input("FORUM_NAME", $forum['name'])
  1709.                                          )      );
  1710.                                          
  1711.         $ADMIN->html .= $SKIN->add_td_row( array( "<b>Forum Description</b><br>You may use HTML - linebreaks 'Auto-Magically' converted to <br>" ,
  1712.                                                   $SKIN->form_textarea("FORUM_DESC", str_replace("<br>", "\n", $forum['description']) )
  1713.                                          )      );
  1714.                                          
  1715.         $ADMIN->html .= $SKIN->add_td_row( array( "<b>Allow HTML to be posted?</b>" ,
  1716.                                                   $SKIN->form_yes_no("FORUM_HTML", $forum['use_html'] )
  1717.                                          )      );
  1718.                                          
  1719.         $ADMIN->html .= $SKIN->add_td_row( array( "<b>Allow IBF CODE to be posted?</b>" ,
  1720.                                                   $SKIN->form_yes_no("FORUM_IBC", $forum['use_ibc'] )
  1721.                                          )      );
  1722.                                          
  1723.         //-----------
  1724.                                          
  1725.         $ADMIN->html .= $SKIN->add_td_row( array( "<b>Allow Polls in this forum (when allowed)?</b>" ,
  1726.                                                   $SKIN->form_yes_no("allow_poll", $forum['allow_poll'] )
  1727.                                          )      );
  1728.         
  1729.         $ADMIN->html .= $SKIN->add_td_row( array( "<b>Allow votes to bump a topic?</b>" ,
  1730.                                                   $SKIN->form_yes_no("allow_pollbump", $forum['allow_pollbump'] )
  1731.                                          )      );
  1732.         
  1733.         $ADMIN->html .= $SKIN->add_td_row( array( "<b>Posts in this forum increase member post count?</b>" ,
  1734.                                                   $SKIN->form_yes_no("inc_postcount", $forum['inc_postcount'] )
  1735.                                          )      );
  1736.                                          
  1737.         //-----------
  1738.         
  1739.         $ADMIN->html .= $SKIN->add_td_row( array( "<b>Allow post uploads?</b>" ,
  1740.                                                   $SKIN->form_yes_no("ALLOW_ATTACH", $forum['use_attach'] )
  1741.                                          )      );
  1742.         
  1743.         $ADMIN->html .= $SKIN->add_td_row( array( "<b>Preview all posts?</b><br>(Requires a moderator to manually add posts to the forum)" ,
  1744.                                                   $SKIN->form_yes_no("MODERATE", $forum['preview_posts'] )
  1745.                                          )      );
  1746.                                          
  1747.         $ADMIN->html .= $SKIN->add_td_row( array( "<b>Require password access?<br>Enter the password here</b><br>(Leave this box empty if you do not require this)" ,
  1748.                                                   $SKIN->form_input("FORUM_PROTECT", $forum['password'])
  1749.                                          )      );
  1750.                                          
  1751.         $ADMIN->html .= $SKIN->add_td_row( array( "<b>Default date cut off for topic display</b>" ,
  1752.                                                   $SKIN->form_dropdown( "PRUNE_DAYS",
  1753.                                                                             array( 
  1754.                                                                                     0 => array( 1, 'Today' ),
  1755.                                                                                     1 => array( 5, 'Last 5 days'  ),
  1756.                                                                                     2 => array( 7, 'Last 7 days'  ),
  1757.                                                                                     3 => array( 10, 'Last 10 days' ),
  1758.                                                                                     4 => array( 15, 'Last 15 days' ),
  1759.                                                                                     5 => array( 20, 'Last 20 days' ),
  1760.                                                                                     6 => array( 25, 'Last 25 days' ),
  1761.                                                                                     7 => array( 30, 'Last 30 days' ),
  1762.                                                                                     8 => array( 60, 'Last 60 days' ),
  1763.                                                                                     9 => array( 90, 'Last 90 days' ),
  1764.                                                                                     10=> array( 100,'Show All'     ),
  1765.                                                                                  ),
  1766.                                                                           $forum['prune']
  1767.                                                                         )
  1768.                                          )      );
  1769.                                          
  1770.         $ADMIN->html .= $SKIN->add_td_row( array( "<b>Default sort key</b>" ,
  1771.                                                   $SKIN->form_dropdown( "SORT_KEY",
  1772.                                                                             array( 
  1773.                                                                                     0 => array( 'last_post', 'Date of the last post' ),
  1774.                                                                                     1 => array( 'title'    , 'Topic Title' ),
  1775.                                                                                     2 => array( 'starter_name', 'Topic Starters Name' ),
  1776.                                                                                     3 => array( 'posts'    , 'Topic Posts' ),
  1777.                                                                                     4 => array( 'views'    , 'Topic Views' ),
  1778.                                                                                     5 => array( 'start_date', 'Date topic started' ),
  1779.                                                                                     6 => array( 'last_poster_name'   , 'Name of the last poster' ),
  1780.                                                                                  ),
  1781.                                                                           $forum['sort_key']
  1782.                                                                         )
  1783.                                          )      );
  1784.                                          
  1785.         $ADMIN->html .= $SKIN->add_td_row( array( "<b>Default sort order</b>" ,
  1786.                                                   $SKIN->form_dropdown( "SORT_ORDER",
  1787.                                                                             array( 
  1788.                                                                                     0 => array( 'Z-A', 'Descending (Z - A, 0 - 10)' ),
  1789.                                                                                     1 => array( 'A-Z', 'Ascending (A - Z, 10 - 0)' ),
  1790.                                                                                  ),
  1791.                                                                           $forum['sort_order']
  1792.                                                                         )
  1793.                                          )      );
  1794.                                          
  1795.  
  1796.         $ADMIN->html .= $SKIN->end_form("Edit this forum");
  1797.                                          
  1798.         $ADMIN->html .= $SKIN->end_table();
  1799.         
  1800.         $ADMIN->output();
  1801.             
  1802.             
  1803.     }
  1804.  
  1805.  
  1806.     //+---------------------------------------------------------------------------------
  1807.     
  1808.     function do_edit() {
  1809.         global $IN, $root_path, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP, $HTTP_POST_VARS;
  1810.         
  1811.         $IN['FORUM_NAME'] = trim($IN['FORUM_NAME']);
  1812.         
  1813.         if ($IN['FORUM_NAME'] == "")
  1814.         {
  1815.             $ADMIN->error("You must enter a forum title");
  1816.         }
  1817.         
  1818.         $cat    = -1;
  1819.         $parent = -1;
  1820.         
  1821.         if ( preg_match( "/^c_(\d+)$/", $IN['CATEGORY'], $match ) )
  1822.         {
  1823.             $cat = $match[1];
  1824.         }
  1825.         else
  1826.         {
  1827.             $parent = preg_replace( "/^f_/", "", $IN['CATEGORY'] );
  1828.             
  1829.             $DB->query("SELECT category FROM ibf_forums WHERE id='$parent'");
  1830.             
  1831.             if ($forum_result = $DB->fetch_row())
  1832.             {
  1833.                 $cat = $forum_result['category'];
  1834.             }
  1835.         }
  1836.         
  1837.         $db_string = $DB->compile_db_update_string( array (
  1838.                                                             
  1839.                                                             'name'              => $IN['FORUM_NAME'],
  1840.                                                             'description'       => str_replace( "\n", "<br>", stripslashes($HTTP_POST_VARS['FORUM_DESC']) ),
  1841.                                                             'use_ibc'           => $IN['FORUM_IBC'],
  1842.                                                             'use_html'          => $IN['FORUM_HTML'],
  1843.                                                             'status'            => $IN['FORUM_STATUS'],
  1844.                                                             'password'          => $IN['FORUM_PROTECT'],
  1845.                                                             'category'          => $cat,
  1846.                                                             'sort_key'          => $IN['SORT_KEY'],
  1847.                                                             'sort_order'        => $IN['SORT_ORDER'],
  1848.                                                             'prune'             => $IN['PRUNE_DAYS'],
  1849.                                                             'use_attach'        => $IN['ALLOW_ATTACH'],
  1850.                                                             'preview_posts'     => $IN['MODERATE'],
  1851.                                                             'allow_poll'        => $IN['allow_poll'],
  1852.                                                             'allow_pollbump'    => $IN['allow_pollbump'],
  1853.                                                             'inc_postcount'     => $IN['inc_postcount'],
  1854.                                                             'parent_id'         => $parent
  1855.                                                             
  1856.                                                   )       );
  1857.                                                   
  1858.         $DB->query("UPDATE ibf_forums SET $db_string WHERE id='".$IN['f']."'");
  1859.         
  1860.         $ADMIN->done_screen("Forum {$IN['CAT_NAME']} Edited", "Forum Control", "act=cat" );
  1861.         
  1862.         
  1863.         
  1864.     }
  1865.     
  1866.     
  1867.     
  1868.     //+---------------------------------------------------------------------------------
  1869.     //
  1870.     // EDIT FORUM
  1871.     //
  1872.     //+---------------------------------------------------------------------------------
  1873.     
  1874.     function perm_edit_form() {
  1875.         global $IN, $root_path, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP;
  1876.         
  1877.         if ($IN['f'] == "")
  1878.         {
  1879.             $ADMIN->error("You didn't choose a forum to edit, duh!");
  1880.         }
  1881.         
  1882.         $cats = array();
  1883.         
  1884.         $DB->query("SELECT id,name FROM ibf_categories ORDER BY position");
  1885.         
  1886.         while ( $r = $DB->fetch_row() )
  1887.         {
  1888.             $cats[] = array( $r['CAT_ID'] , $r['CAT_NAME'] );
  1889.         }
  1890.         
  1891.         $DB->query("SELECT * FROM ibf_forums WHERE id='".$IN['f']."'");
  1892.         $forum = $DB->fetch_row();
  1893.         
  1894.         if ($forum['id'] == "")
  1895.         {
  1896.             $ADMIN->error("Could not retrieve the forum data based on ID {$IN['f']}");
  1897.         }
  1898.         
  1899.         
  1900.         
  1901.         
  1902.         $ADMIN->page_title = "Edit permissions for ".$forum['name'];
  1903.         
  1904.         $ADMIN->page_detail = "This section will allow you to edit an existing forum. If you wish to adjust the forum permissions (who has the ability to
  1905.                                start, reply and read topics) click on 'Edit Permissions on the Forums and Categories overview.";
  1906.         
  1907.         //+-------------------------------
  1908.         
  1909.         $ADMIN->html .= $SKIN->start_form( array( 1 => array( 'code'  , 'pdoedit'  ),
  1910.                                                   2 => array( 'act'   , 'forum'   ),
  1911.                                                   3 => array( 'f'     , $IN['f']  ),
  1912.                                             ) );
  1913.         
  1914.         $SKIN->td_header[] = array( " "  , "40%" );
  1915.         $SKIN->td_header[] = array( " "  , "60%" );
  1916.         
  1917.         $ADMIN->html .= $SKIN->start_table( "Forum Access Permissions" );
  1918.         
  1919.         $ADMIN->html .= $SKIN->add_td_row( array( "<b>Forum access permissions</b><br>(Check box for access, uncheck to not allow access)<br>If you deny read access for a member group, they will not see the forum" ,
  1920.                                                   $SKIN->build_group_perms($forum['read_perms'], $forum['start_perms'], $forum['reply_perms'])
  1921.                                          )      );
  1922.                                          
  1923.  
  1924.         $ADMIN->html .= $SKIN->end_form("Edit this forum");
  1925.                                          
  1926.         $ADMIN->html .= $SKIN->end_table();
  1927.         
  1928.         $ADMIN->output();
  1929.             
  1930.             
  1931.     }
  1932.  
  1933.  
  1934.     function perm_do_edit() {
  1935.         global $IN, $root_path, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP;
  1936.         
  1937.         $perms = $ADMIN->compile_forum_perms();
  1938.         
  1939.         
  1940.         $db_string = $DB->compile_db_update_string( array (
  1941.                                                             
  1942.                                                             'start_perms' => $perms['START'],
  1943.                                                             'reply_perms' => $perms['REPLY'],
  1944.                                                             'read_perms'  => $perms['READ'],
  1945.                                                             
  1946.                                                   )       );
  1947.                                                   
  1948.         $DB->query("UPDATE ibf_forums SET $db_string WHERE id='".$IN['f']."'");
  1949.         
  1950.         $ADMIN->done_screen("Forum Access Permissions Edited", "Forum Control", "act=cat" );
  1951.         
  1952.         
  1953.         
  1954.     }
  1955.     
  1956.         
  1957. }
  1958.  
  1959.  
  1960. ?>